package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.tracing.dtrace.ProviderAttributes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(description = "平台属性管理")
@RequestMapping("/admin/product")

public class BaseManagerController {

    @Autowired
    private ManagerService managerService;


    @GetMapping("/getCategory1")
    @ApiOperation("一级分类查询")
    public Result getCategory1(){
       List<BaseCategory1> list =  managerService.getCategory1List();
       return Result.ok(list);
    }

    @GetMapping("/getCategory2/{category1Id}")
    @ApiOperation("二级分类查询")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> list =  managerService.getCategory2List(category1Id);
        System.out.println(list);
        return Result.ok(list);
    }


    @GetMapping("/getCategory3/{category2Id}")
    @ApiOperation("三级分类查询")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> list =  managerService.getCategory3List(category2Id);
        return Result.ok(list);
    }

    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    @ApiOperation("平台属性查询")
    public Result attrInfoList(
            @PathVariable Long category1Id,
            @PathVariable Long category2Id,
            @PathVariable Long category3Id){
       List<BaseAttrInfo> list =  managerService.getAttrInfoList(category1Id,category2Id,category3Id);
       return Result.ok(list);
    }

    @PostMapping("/saveAttrInfo")
    @ApiOperation("添加与更新平台属性")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        Long attrInfoId = baseAttrInfo.getId();
        System.out.println(baseAttrInfo);
        System.out.println(attrInfoId);
        if(attrInfoId==null){
            managerService.saveAttrInfo(baseAttrInfo);
        }else{
            managerService.updateAttrInfo(baseAttrInfo);
        }
        return Result.ok();
    }
    @GetMapping("/getAttrValueList/{attrId}")
    @ApiOperation("根据平台属性ID获取平台属性")
    public Result getAttrValueListByAttrId(@PathVariable Long attrId){
       List<BaseAttrValue> list =  managerService.getAttrValueListByAttrId(attrId);
       return Result.ok(list);
    }
    @ApiOperation("品牌分页列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademarkPage(@PathVariable Integer page,@PathVariable Integer limit){
           Page<BaseTrademark> TrademarkPage =  managerService.baseTrademarkPage(page,limit);
           return Result.ok(TrademarkPage);
    }
    @ApiOperation("根据ID查询品牌")
    @GetMapping("/baseTrademark/get/{id}")
    public Result baseTrademarkById(@PathVariable Long id){
        BaseTrademark trademark = managerService.baseTrademarkById(id);
        return Result.ok(trademark);
    }

    @ApiOperation("添加品牌")
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        managerService.saveBaseTrademark(baseTrademark);
        return Result.ok();
    }
    @ApiOperation("更新品牌")
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        managerService.updateBaseTrademark(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result removeBaseTrademark(@PathVariable Long id){
        managerService.removeBaseTrademark(id);
        return Result.ok();
    }

}
